import java.io.IOException;

import jxl.write.WriteException;

public class TestSetup {

	public static void main(String[] args) {

		Tester test;
		SpreadsheetMaker xcelSheet;
		Sorter[] algorithms;
		String[] labels;
		double[][] runTimes;
		int firstElement;
		int lastElement;
		int nrOfSteps;
		int nrOfReps;

		// Order of arguments should be: interval start integer, interval end
		// integer, number of steps to divide the interval into, number of
		// repetitions of each step interval, sorting method keyword(s).
		if (args.length < 5) {
			System.out
					.println("\n-You have to provide the following arguments-");
			System.out.println("1: First integer in interval,");
			System.out.println("2: Last integer in interval,");
			System.out
					.println("3: Number of steps the interval should be clocked,");
			System.out
					.println("4: How many times each step interval should be repeated,");
			System.out
					.println(">4: Sorting algorithm(s) to test using atleast one of the following keyword(s):");
			System.out.println("heap: heapsort algorithm");
			System.exit(-1);
		}

		firstElement = Integer.parseInt(args[0]);
		lastElement = Integer.parseInt(args[1]);
		nrOfSteps = Integer.parseInt(args[2]);
		nrOfReps = Integer.parseInt(args[3]);
		algorithms = new Sorter[args.length - 4];
		labels = new String[args.length - 4];

		// Will be extended with more options as more algorithms are implemented
		for (int i = 4; i < args.length; i++) {
			labels[i - 4] = args[i];
			if (args[i].equals("heap")) {
				algorithms[i - 4] = new Heapsort();
			}
		}

		test = new Tester(firstElement, lastElement, nrOfReps, nrOfSteps,
				algorithms);
		runTimes = test.startTesting();

		xcelSheet = new SpreadsheetMaker();
		try {
			xcelSheet.makeSpreadsheet(runTimes, labels, test.getStepArray());
		} catch (WriteException | IOException e) {
			System.out.println("Could not create spreadsheet!");
		}
		System.out.println("All tests have finished.");

	}
}
